﻿Chenxin.UI.IncomeSummeryPersonal = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/Reports/IncomeSummaryPersonal.ashx',
    createSearch: function() {
        this.personalsearch = new Chenxin.UI.IncomeSummeryPersonalSearch({
            scope: this
        });
        return this.personalsearch;
    },
    showDetails: function(empid) {
        if (!this.detailsWin) {
            this.detailsWin = new Chenxin.UI.IncomeSummeryPersonalWin({
                id: 'x_details_win',
                actionUrl: this.actionUrl + '?op=getdtailslist'
            });
        }
        this.detailsWin.show();
        var title = '';
        title += '详情';

        this.detailsWin.setTitle(title);
        this.detailsWin.grid.param = {}
        this.detailsWin.grid.param.empid = empid;

        paramStr = this.personalsearch.getParamJson();
        Chenxin.apply(this.detailsWin.grid.param, paramStr)
        this.detailsWin.grid.reload();
    },
    initEvent: function() {
        var _this = this;
        $('.btn_viewdetails').live('click', function() {
            _this.showDetails($(this).attr('r'));
        });
    },
    createGrid: function() {
        _this = this;
        return new Chenxin.UI.JsonGrid({
            createTitleTool: function() {
                return [{
                    text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
                    scope: this,
                    title: '导出全部数据',
                    handler: function(el) {
                        _this.exportAll();
                    }
}];
                },
                actionUrl: this.actionUrl + '?op=getlist',
                pageSize: 50,
                height: 400,
                renderTo: 'divShowBalanceList',
                hasCheckBox: false,
                scope: this,
                autoLoad: false,
                id: 'BalanceList',
                modelId: 'UserId',
                title: '个人实收统计表',
                scope: this,
                columns: {
                    UserCode: { head: '员工编号', width: 120, sortable: true },
                    UserName: { head: '员工姓名', width: 100, sortable: true },
                    Business: { head: '所在商圈', width: 100, sortable: true },
                    DepartName: { head: '所在门店', width: 120, sortable: true },
                    Income: { head: '个人实收', width: 100, sortable: true },
                    operate: {
                        head: '查看详细',
                        width: 100,
                        renderer: function(val, c, row) {
                            if (row.UserId)
                                return '<a title="查看详细" class="btn_viewdetails" r="' + row.UserId + '" style="cursor:pointer">查看详细</a>';
                            else
                                return '';
                        }
                    }
                }
            });
        },
        exportAll: function() {
            _this = this;
            paramStr = this.search.getParamJson();
            paramStr.op = 'exportAll';
            Chenxin.Msg.Waiting.show();
            Chenxin.Fn.exportToExcelByServer(this.actionUrl, paramStr, '导出文件');
            //$.ajax({ url: this.actionUrl, data: paramStr,async:false});
            Chenxin.Msg.Waiting.hide();
        },
        initComponent: function() {
            Chenxin.UI.IncomeSummeryPersonal.superclass.initComponent.call(this);
        }
    });


Chenxin.UI.IncomeSummeryPersonalWin=Chenxin.extend(Chenxin.UI.Win,{	
	id:'',
	actionUrl:'',
	width:680,
	hasFoot:true,
	height:360,
	content:'<div id="x_details_grid"></div>',
	createBtn:function(){
		return [{
			text:'刷新',
			handler:this.refreshGrid
		},{
			text:'关闭',
			handler:this.hide
		}]	
	},
	refreshGrid:function(){
		this.grid.reload();
	},
	createGrid:function(){
		if(this.grid){
			return;
		}
		this.grid = new Chenxin.UI.ReportGrid({
			autoLoad:false,
			actionUrl:this.actionUrl,
            id: 'x_details_grid',
            renderTo: 'x_details_grid',
            hasCheckBox: false,
            modelId: 'a',
            cellBorder: true,
            scope: this,
			height:311,
			hasTitle:false,
			columns:{
			Business: { head: '商圈', width: 100, sortable: true, captionCol: true },
			PointDepart: { head: '门店', width: 150, sortable: true, inTotal: false },
			ContractCode: { head: '成交编号', width: 150, sortable: true, inTotal: false },
			ContractDate: { head: '成交日期', width: 100, sortable: true, inTotal: false },
			Region: { head: '区域', width: 100, sortable: true, inTotal: false },
			HouseAddress: { head: '房屋地址', width: 200, sortable: true, inTotal: false },
			PointEmp: { head: '业务员', width: 100, sortable: true, inTotal: false },
			DeparterManagerName: { head: '店长', width: 100, sortable: true, inTotal: false },
			MangerName: { head: '高级经理', width: 100, sortable: true, inTotal: false },
			MajordomoName: { head: '总监', width: 100, sortable: true, inTotal: false },
			RealCommisionFinal: { head: '应收佣收', width: 100, sortable: true, inTotal: false },
			CommisionFinal: { head: '折佣', width: 100, sortable: true, inTotal: false },
			ConsultingFinal: { head: '咨询费', width: 100, sortable: true, inTotal: false },
			Results: { head: '业绩', width: 100, sortable: true, inTotal: false },
			Point: { head: '点数', width: 100, sortable: true, inTotal: false },
				ApportionRealCommisionFinal:{head:'分摊应收',width:100,sortable:true},
				ApportionCommisionFinal:{head:'分摊咨询费',width:100,sortable:true},
				ApportionConsultingFinal:{head:'分摊业绩',width:100,sortable:true},
				PayMoney:{head:'实收',width:100,sortable:true},
				ApportionPay:{head:'分摊实收',width:100,sortable:true},
				ContractArchDate: { head: '业绩归属日期', width: 100, sortable: true, inTotal: false },
				BargainCompanyName: { head: '合同归属公司', width: 100, sortable: true, inTotal: false }
			}
		});
	},
	initComponent:function(){
		Chenxin.UI.IncomeSummeryPersonalWin.superclass.initComponent.call(this);
		this.createGrid();
	}
});

/*
* 查询面板
*/
Chenxin.UI.IncomeSummeryPersonalSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'divCondition',
    createComboList: function() {
		var _this=this;		
        //人员
        this.comboUserId = new Chenxin.UI.RichModelTreeCombo({
            textBoxId: 'txtUser',
            txtModelName: 'UserName',
            singleSelect: true,
            name: 'empid'
        });
		
        this.combl = new Chenxin.UI.StructComboList({
            cityAfterSelected: function() {
                _this.comboUserId.reset();
            },
            companyAfterSelected: function() {
                _this.comboUserId.reset();
            },
            businessDistrictAfterSelected: function() {
                _this.comboUserId.reset();
            },
            departsAfterSelected: function(val) {
                _this.comboUserId.reset();
                if (val != '请选择') {
                    _this.comboUserId.loadUser(val, 500);
                }
            }
        });
		
		
		
        //收支情况
        var AchievementType = new Chenxin.UI.Combo({
            containerId: '#AchievementType',
            tbxWidth: 45,
			name:'BusinessType',
            items: comboCommon.AchievementType
        });
		
        var structs = this.combl.comboList;
        structs.push(this.comboUserId);
        structs.push(AchievementType);
        return this.combl.comboList;
    },
    initEvent: function() {
        $(".x_date").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        })
		$('#txtKeyword').defText({
            deftxt: '地址/成交编号/员工编号'
        });

        var curdate = new Date();
        $('#txtActualDate').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1));
        $("#txtActualDate").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
		
        var objSrh = this;
        /*********事件：检索按钮*********/
        $("#btSearch").click(function() {
            objSrh.scope.reloadGrid();
        });
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.IncomeSummeryPersonal();
});